package com.diandian.backend.client.controller;

import com.diandian.backend.client.param.*;
import com.diandian.backend.client.service.PermissionService;
import com.diandian.base.boot.starter.response.BaseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    private static final Logger logger = LoggerFactory.getLogger(PermissionController.class);

    @Autowired
    private PermissionService permissionService;

    @PostMapping("/page")
    public BaseResult page(@RequestBody ClientPermissionPageParam param) {
        param.check();
        return new BaseResult(0, "success", permissionService.page(param.toDTO()));
    }

    @PostMapping("/add")
    public BaseResult add(@RequestBody ClientPermissionAddParam param) {
        permissionService.add(param.toDTO());
        return new BaseResult(0, "success", null);
    }

    @PostMapping("/detail")
    public BaseResult detail(@RequestBody PermissionDetailParam param) {
        return new BaseResult(0, "success", permissionService.getDetail(param.toDTO()));
    }

    @PostMapping("/updateById")
    public BaseResult updateById(@RequestBody ClientPermissionUpdateByIdParam param) {
        param.check();
        permissionService.updateById(param.toDTO());
        return new BaseResult(0, "success", null);
    }

    @PostMapping("/deleteById")
    public BaseResult deleteById(@RequestBody ClientPermissionDeleteByIdParam param) {
        param.check();
        permissionService.deleteById(param.toDTO());
        return new BaseResult(0, "success", null);
    }

}
